package com.jieshen.lesson3;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * 当鼠标悬浮在界面上的时候，设置title为欢迎
 *  当鼠标离开窗口时，设置title为欢迎下次再来
 */
public class WindowTest {
    public static void main(String[] args) {
        new WindowFrame();
    }
}

class WindowFrame extends Frame{
    public WindowFrame(){
        setBackground(Color.blue);
        setBounds(100,100,200,200);
        setVisible(true);
//        addWindowListener(new MyWindowListener());
        addWindowListener(
                new WindowAdapter() {

                    @Override
                    public void windowActivated(WindowEvent e) {
                        WindowFrame source = (WindowFrame) e.getSource();
                        source.setTitle("欢迎登陆");
                    }

                    @Override
                    public void windowClosing(WindowEvent e) {
                        System.out.println("windowClosing");
                    }

                    @Override
                    public void windowDeactivated(WindowEvent e) {
                        WindowFrame source = (WindowFrame) e.getSource();
                        source.setTitle("欢迎下次再来");
                    }
                }
        );
    }

    class MyWindowListener extends WindowAdapter{
        @Override
        public void windowClosing(WindowEvent e) {
            setVisible(false);//隐藏窗口，通过按钮隐藏窗口
            System.exit(0);
        }
    }
}


